package org.class2table.core.parent;

import org.class2table.core.dictionary.Constants;
import org.class2table.core.parent.bean.EntityAttrMetaData;
import org.class2table.core.parent.bean.PrimaryKeyInfo;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class ParentProcessor {

    public static List<PrimaryKeyInfo> extractPrimaryKeyInfos(List<? extends EntityAttrMetaData> entityAttrMetaDataList){
        return entityAttrMetaDataList.stream().filter(t-> Constants.INFORMATION_SCHEMA.COLUMN_KEY.PRI.equals(t.getColumnKey())).map(
                q->{
                    Integer columnKeySort = q.getColumnKeySort();
                    PrimaryKeyInfo primaryKeyInfo = new PrimaryKeyInfo();
                    primaryKeyInfo.setSort(columnKeySort);
                    primaryKeyInfo.setColumnName(q.getColumnName());
                    return primaryKeyInfo;
                }
        ).sorted(Comparator.comparing(PrimaryKeyInfo::getSort)).collect(Collectors.toList());
    }

}
